package com.chen.lifepic.CommonTest;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.chen.lifepic.DataSource.RequestPicturesURLHelper;
import com.loopj.android.http.JsonHttpResponseHandler;

public class TestPicturesURLActivity extends Activity {
	RequestPicturesURLHelper _helper = null;

	TextView _view = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		_view = new TextView(this);
		ScrollView scrollView = new ScrollView(this);

		scrollView.setLayoutParams(new LinearLayout.LayoutParams(
			LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.MATCH_PARENT));

		_view.setLayoutParams(new LinearLayout.LayoutParams(
			LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.MATCH_PARENT));
		scrollView.addView(_view);
		setContentView(scrollView);

		_view.setText("Loading text...");
		_helper = new RequestPicturesURLHelper(_handler, 0);
	}

	JsonHttpResponseHandler _handler = new JsonHttpResponseHandler() {
		@Override
		public void onSuccess(org.json.JSONObject jsonObject) {
			try {
				JSONArray array = jsonObject.getJSONArray("data");
				int cout = array.length();
				for (int i = 0; i < cout; i++) {
					JSONObject obj = (JSONObject) array.get(i);
					// ��ȡobj,print obj
					// Thread.sleep(500);
					_view.setText(obj.getString("thumbnail_url"));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			// _view.setText(jsonObject.toString());
		};
	};
}
